<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends CommonAction{
	 
	public function index() {
		//echo c('CMS_NAME');
		$len = 10 ; 
		
		$news = new Model('news_view');
		$news_arr = $news->order('News_time desc')->limit($len)->select();
		
		$bull_arr = d('bulletin')->order('seq desc, time desc')->limit($len)->findAll();
		
		import("ORG.Util.Page");
		$gbook = d('guestbook');
		
		$count = $gbook->count();
		$p  = new Page ($count, 5 );
		
		$p->setConfig('header','篇记录');
        $p->setConfig('prev',"<");
        $p->setConfig('next','>');
        $p->setConfig('first','<<');
        $p->setConfig('last','>>');
	        
		$guestbook_arr = $gbook->order('gtime desc')->limit($p->firstRow.','.$p->listRows)->findAll();		
		
		//$json['page'] = $this->ajax_page($p->getpage());
		
		$page = $p->show(); 
		
		$this->assign ( "page", $page );
		
		$this->assign('news_list',$news_arr); // 模板变量赋值   
		$this->assign('bull_list',$bull_arr);
		$this->assign('guestbook_arr',$guestbook_arr);
		
		//dump($char_result);
		$this->display(); // 输出模板   
		
	
	 }  

	public function ajax_page($page_array=array(),$step=5){
	 	
		
		
		if ($page_array['totalPages'] >1){
			$page['first'] = 1;
	        $pre = intval($page_array['nowPage']/$step);  
	        
			$pre >0 ? $first = $page_array['nowPage']-$step : $first = $pre*$step+1 ;
			$pre >0 ? $end   = $page_array['nowPage']+$step : $end   = ($pre+1)*$step;
			
			
			if ($end >$page_array['totalPages']){
				$first = $page_array['totalPages'] - $step;
				$end   = $page_array['totalPages'];
			}
	        
			$first <1 ? $first = 1 : $first = $first;
	        
			for($i=$first; $i<=$end; $i++){
				if($i != $page_array['nowPage']){
					$page['list'][$i]['id']  = $i;
					$page['list'][$i]['act'] = 1;
				}
				else{
					$page['list'][$i]['id']  = $i;
					$page['list'][$i]['act'] = 0;                                 
				}
			}       
			$page['end'] = $page_array['totalPages'];
		}		
		return $page;
	}
	 

}
?>